﻿using System;
using System.Collections.Generic;
using System.Web;

using CE.Company;
using CE.Mail;
/// <summary>
/// Summary description for Welcome
/// </summary>

namespace CE.Email
{
    public class Welcome
    {
        //private string _emailTo;
        //private string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CXWelcome_CC"].ToString();
        //private string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CXWelcome_BCC"].ToString();

        public Welcome()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public static bool SendMail(string EmailAddress, string UserName, string AuthCode)
        {
            bool _retVal = false;
            try
            {
                string _emailTo = EmailAddress;
                string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CXWelcome_CC"].ToString();
                string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CXWelcome_BCC"].ToString();
                string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
                string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");
                string _customername = UserName;                
                string _emailSubject = Resources.WelcomeEmail.Subject;  

                CompanyInformation _company = new CompanyInformation();
                CompanyInformationDB _companydb = new CompanyInformationDB();
                _company = _companydb.GetCompanyInformation(2);
                string _companyAddress = "";
                string _emailaddress = "";
                string _websiteaddress = "";
                if (_company != null)
                {
                    _companyAddress = _company.Address1;
                    _emailaddress = _company.EmailAddress;
                    _websiteaddress = _company.Website;
                }
                _company = null;
                _companydb = null;

                string _mailBody = "";

                #region "mailbody"
                _mailBody = Resources.WelcomeEmail.Hi + " " + _customername + ",";
                _mailBody += "<br />";
                _mailBody += Resources.WelcomeEmail.Body1;
                _mailBody += "<br /><br />";
                _mailBody += Resources.WelcomeEmail.Body2;
                //_mailBody += "<br /><br />You may now log in to  <a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a> using the following username and password.";
                _mailBody += "<br /><br />"+ Resources .WelcomeEmail.Body3;
                _mailBody += "<br /><br />Username : " + EmailAddress;
                _mailBody += "<br />Password : " + AuthCode;
                _mailBody += "<br /><br />";
                _mailBody += Resources.WelcomeEmail.Body4;
                _mailBody += "<br /><br />";
                _mailBody += Resources.WelcomeEmail.Body5;
                _mailBody += "<br /><br />";
                _mailBody += Resources.WelcomeEmail.Body6;
                _mailBody += "<br /><br />" + Resources.WelcomeEmail.BestRegards + ",<br /><br />www.gluaygluay.com Support";
                _mailBody += " <br /><br /><img src='" + imgLogoUrl + "' />";
                _mailBody += "<br />" + _companyAddress;
                _mailBody += "w   :  <a href='http://www.gluaygluay.com' target='_blank'>www.gluaygluay.com</a><br /><hr />";
                _mailBody += "<br /><i>This is a computer-generated email. Please do not reply to this email.</i>";
                #endregion

                if (MailManagerTH.SendWelcomeMessage(_emailTo, _emailCC, _emailBCC, _emailSubject, _mailBody))
                {
                    _retVal = true;
                }
                else
                {
                    _retVal = false;
                }
            }
            catch (Exception Ex)
            {
                _retVal = false;               
                
            }

            return _retVal;
        }
    }
}
